package com.webserver.controller;

import com.webserver.annotation.Controller;
import com.webserver.annotation.RequestMapping;
import com.webserver.http.HttpServletRequest;
import com.webserver.http.HttpServletResponse;
import qrcode.QRCodeUtil;

@Controller
public class ToolsController {

    @RequestMapping("/myweb/createQR")
    public void creatQR(HttpServletRequest request, HttpServletResponse response){
        String line = request.getParameter("content");
        response.setContentType("image/jpeg");

        try {
            QRCodeUtil.encode(line,"./Ikun.jpg",
                    response.getOutputStream(),//将生成的图片写出到数组中
                    true);
            System.out.println("二维码生成了");
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    public static void main(String[] args) {
        String line = "扫你妹！";
        try {
//            QRCodeUtil.encode(line,"./qr.jpg");

            QRCodeUtil.encode(line,"./Ikun.jpg","./qr.jpg",true);
            System.out.println("二维码已生成");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
